package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Realtime;
import com.stylefeng.guns.modular.system.service.IRealtimeService;
import com.stylefeng.guns.modular.system.warpper.RealTimeWarpper;

/**
 * 实时盘口控制器
 *
 * @author fengshuonan
 * @Date 2018-06-27 20:41:04
 */
@Controller
@RequestMapping("/realtime")
public class RealtimeController extends BaseController {

    private String PREFIX = "/system/realtime/";

    @Autowired
    private IRealtimeService realtimeService;

    /**
     * 跳转到实时盘口首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "realtime.html";
    }

    /**
     * 跳转到添加实时盘口
     */
    @RequestMapping("/realtime_add")
    public String realtimeAdd() {
        return PREFIX + "realtime_add.html";
    }

    /**
     * 跳转到修改实时盘口
     */
    @RequestMapping("/realtime_update/{realtimeId}")
    public String realtimeUpdate(@PathVariable Integer realtimeId, Model model) {
        Realtime realtime = realtimeService.selectById(realtimeId);
        model.addAttribute("item",realtime);
        LogObjectHolder.me().set(realtime);
        return PREFIX + "realtime_edit.html";
    }

    /**
     * 获取实时盘口列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String gScode, @RequestParam(required = false) String gTime,@RequestParam(required = false) Integer gType) {
    	Page<Realtime> page = new PageFactory<Realtime>().defaultPage();
    	List<Map<String, Object>> gdhs = realtimeService.selectMapsByDm(page,gScode,gTime,gType);
    	page.setRecords((List<Realtime>) new RealTimeWarpper(gdhs).warp());
        return super.packForBT(page);
    }
    
    /**
     * 新增实时盘口
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Realtime realtime) {
        realtimeService.insert(realtime);
        return SUCCESS_TIP;
    }

    /**
     * 删除实时盘口
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer realtimeId) {
        realtimeService.deleteById(realtimeId);
        return SUCCESS_TIP;
    }

    /**
     * 修改实时盘口
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Realtime realtime) {
        realtimeService.updateById(realtime);
        return SUCCESS_TIP;
    }

    /**
     * 实时盘口详情
     */
    @RequestMapping(value = "/detail/{realtimeId}")
    @ResponseBody
    public Object detail(@PathVariable("realtimeId") Integer realtimeId) {
        return realtimeService.selectById(realtimeId);
    }
}
